*This do-file is to execute the analysis for the article entitled "Behavioral and financial coping strategies among energy-insecure households"*
*Authors: Sanya Carley, Michelle Graff, David Konisky, Trevor Memmott*
*Corresponding author: Sanya Carley; scarley@indiana.edu*


*Run this do-file after running the coding do-file, entitled "CopingStrategies_CODING_1"*

***************
*Import Data
***************

capture log close
log 	using Analysis.log, replace text
clear 	all
macro 	drop _all
set 	linesize 80
set 	scheme economist
ssc		install outreg2

use CodedCleaned_4waves.dta, replace


***************************
*Prep the data for analysis
***************************
sort id wave
order id wave

*Set Weights*
svyset id [pweight=weight]

*set globals*
global HHdems "any_under5 any_over65 any_disability electronic_device black hispanic other_race2 educ_HS FPL_100_150 under_100_fpl employed"
global home_features "bad_housecondition home_renter home_other hometype_trailer hometype_apartmentcondo hometype_other"
global region "west northeast midwest"
global climateregion "northeast_climateregion uppermidwest_climateregion southeast_climateregion rockiesplains_climateregion south_climateregion southwest_climateregion northwest_climateregion west_climateregion alaska_climateregion hawaii_climateregion"

xi i.state

keep if wave==2|wave==3|wave==4
	
****************************
* Main models
****************************

set scheme s1color

*Summary statistics (Table 2 and Table 3)*
svy: reg risky_behavior lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state

svy: mean risky_behavior forego_expenses cope_payasst cope_billstrategy govt_asst_comb network_payasst energy_provider bank_payasst utilitybill_pay_irregular some_debt num_coping lhhbill EI3previously any_under5 any_over65 any_disability electronic_device black hispanic other_race2 white educ_HS under_100_fpl FPL_100_150 FPL_150_200 unemployed bad_housecondition home_renter home_other home_owner hometype_trailer hometype_apartmentcondo hometype_other wave2 wave3 wave4 if e(sample)
svy: mean west south northeast midwest northeast_climateregion uppermidwest_climateregion ohiovalley_climateregion southeast_climateregion rockiesplains_climateregion south_climateregion southwest_climateregion northwest_climateregion west_climateregion alaska_climateregion hawaii_climateregion if e(sample)

svy: reg some_debt lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state
svy: mean some_debt if e(sample)


*Look at trends by wave (Figure 2)*
label define wave_label 2 "Summer" 3 "Fall/Winter" 4 "Winter/Spring"
label values wave wave_label

svy: reg risky_behavior lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state

svy: reg cope_payasst i.wave if e(sample)
margins wave
marginsplot, recastci(rarea) ciopt(color(%25)) xscale(range(2 4.15)) title("Payment Assistance") ytitle("Proportion of Respondents") xtitle("Wave") saving(tmp1, replace)

svy: reg forego_expenses i.wave if e(sample)
margins wave
marginsplot, recastci(rarea) ciopt(color(%25)) xscale(range(2 4.15)) title("Forgo Expenses") ytitle("Proportion of Respondents") xtitle("Wave") saving(tmp2, replace)

svy: reg risky_behavior i.wave if e(sample)
margins wave
marginsplot, recastci(rarea) ciopt(color(%25)) xscale(range(2 4.15)) title("Temp. Behavior") ytitle("Proportion of Respondents") xtitle("Wave") saving(tmp3, replace)

svy: reg cope_billstrategy i.wave if e(sample)
margins wave
marginsplot, recastci(rarea) ciopt(color(%25)) xscale(range(2 4.15)) title("Bill Strategy") ytitle("Proportion of Respondents") xtitle("Wave") saving(tmp4, replace)


graph combine tmp1.gph tmp2.gph tmp3.gph tmp4.gph, ycommon xcommon saving(Coping, replace)

forvalues i = 1(1)4 {
	erase tmp`i'.gph
	} 
	
	
*Main regressions (Table SI1)*
svy: reg risky_behavior $HHdems $home_features wave2 wave3 i.state
outreg2 using table_si1, replace excel ctitle(Risky Temp Behavior)
svy: reg risky_behavior lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state
est store a
outreg2 using table_si1, append excel ctitle(Risky Temp Behavior)

svy: reg forego_expenses $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si1, append excel ctitle(Forgo Expenses)
svy: reg forego_expenses lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state 
est store b
outreg2 using table_si1, append excel ctitle(Forgo Expenses)

svy: reg cope_payasst $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si1, append excel ctitle(Payment Assistance)
svy: reg cope_payasst lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state
est store c
outreg2 using table_si1, append excel ctitle(Payment Assistance)

svy: reg cope_billstrategy $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si1, append excel ctitle(Bill Strategy)
svy: reg cope_billstrategy lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state 
est store d
outreg2 using table_si1, append excel ctitle(Bill Strategy)


*Graph for regression set 1 (Figure 3)*
label variable EI3previously "Previously Disconnected"
label variable lhhbill "Lagged Unable Pay Bill"
label variable any_under5 "Children Under 5"
label variable bad_housecondition "Poor Housing Conditions"
label variable electronic_device "E-Medical Device"
label variable black "Black"
label variable hispanic "Hispanic"
label variable under_100_fpl "Under 100% FPL"

coefplot a, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Temperature Behavior")
gr save a.gph, replace

coefplot b, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Forgo Expenses")
gr save b.gph, replace

coefplot c, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Payment Assistance")
gr save c.gph, replace

coefplot d, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Bill Strategy")
gr save d.gph, replace

graph combine a.gph b.gph c.gph d.gph, ycommon xcommon col(1) ysize(9) xsize(5.5)
gr export regression_set1.png, replace


*Secondary regressions (Table SI2)*
svy: reg govt_asst_comb $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si2, replace excel ctitle(Govt Asst)
svy: reg govt_asst_comb lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state
est store e
outreg2 using table_si2, append excel ctitle(Govt Asst)

svy: reg network_payasst $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si2, append excel ctitle(Informal Network)
svy: reg network_payasst lhhbill EI3previously $HHdems $home_features  wave2 wave3 i.state 
est store f
outreg2 using table_si2, append excel ctitle(Informal Network)

svy: reg energy_provider $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si2, append excel ctitle(Energy Provider)
svy: reg energy_provider lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state  
est store g
outreg2 using table_si2, append excel ctitle(Energy Provider)

svy: reg bank_payasst $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si2, append excel ctitle(Loan)
svy: reg bank_payasst lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state
est store h
outreg2 using table_si2, append excel ctitle(Loan)

svy: reg utilitybill_pay_irregular lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si2, append excel ctitle(Bill Ballancing)
svy: reg utilitybill_pay_irregular lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state  
est store i
outreg2 using table_si2, append excel ctitle(Bill Ballancing)

svy: reg some_debt $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si2, append excel ctitle(Utility Debt)
svy: reg some_debt lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state
est store j 
outreg2 using table_si2, append excel ctitle(Utility Debt)


*Graph for regression set 2 (Figure 4)*
coefplot e, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Government assistance")
gr save e.gph, replace

coefplot f, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Informal Network")
gr save f.gph, replace

coefplot g, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Energy Provider")
gr save g.gph, replace

coefplot h, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Loan")
gr save h.gph, replace

coefplot i, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Bill Balancing")
gr save i.gph, replace

coefplot j, keep(lhhbill EI3previously any_under5 under_100_fpl bad_housecondition electronic_device black hispanic) xline (0) title ("Utility Debt")
gr save j.gph, replace

graph combine e.gph f.gph g.gph h.gph i.gph j.gph, ycommon xcommon col(2) xsize(5.5)
gr export regression_set2.png, replace


*Poisson regressions (Table SI3) and graph for regressions set 3 (Figure 5)*
label define lhhbill_label 0 "No" 1 "Yes"
label values lhhbill lhhbill_label
label define EI3previously_label 0 "No" 1 "Yes"
label values EI3previously EI3previously_label
label define bad_housecondition_label 0 "No" 1 "Yes"
label values bad_housecondition bad_housecondition_label
label define black_label 0 "No" 1 "Yes"
label values black black_label
label define hispanic_label 0 "No" 1 "Yes"
label values hispanic hispanic_label
label define meddevice_label 0 "No" 1 "Yes"
label values electronic_device meddevice_label
label define under100_label 0 "No" 1 "Yes"
label values under_100_fpl under100_label

*Poisson regressions (Table SI3)*
poisson num_coping lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state [pweight=weight]
outreg2 using table_si3, replace excel ctitle(Count of Strategies)

margins, at(lhhbill=(0(1)1))
marginsplot, ytitle("") title("")
gr save k.gph, replace
margins, at(EI3previously=(0(1)1))
marginsplot, ytitle("") title("")
gr save l.gph, replace
margins, at(any_under5=(0(1)1))
marginsplot, ytitle("") title("")
gr save m.gph, replace
margins, at(bad_housecondition=(0(1)1))
marginsplot, ytitle("") title("")
gr save n.gph, replace
margins, at(black=(0(1)1))
marginsplot, ytitle("") title("")
gr save o.gph, replace
margins, at(hispanic=(0(1)1))
marginsplot, ytitle("") title("")
gr save p.gph, replace
margins, at(electronic_device=(0(1)1))
marginsplot, ytitle("") title("")
gr save q.gph, replace
margins, at(under_100_fpl=(0(1)1))
marginsplot, ytitle("") title("")
gr save r.gph, replace

gr combine k.gph l.gph m.gph n.gph o.gph p.gph q.gph r.gph, col(4) xcommon ycommon
gr export regression_set3.png, replace


*Estimates of coping strategy pairings (Table 1)*
gen behavior_forgo = (forego_expenses==1&risky_behavior==1)
gen behavior_payasst = (risky_behavior==1&cope_payasst==1)
gen behavior_bill = (risky_behavior==1&cope_billstrategy==1)
gen forgo_payasst = (forego_expenses==1&cope_payasst==1)
gen forgo_bill = (forego_expenses==1&cope_billstrategy==1)
gen payasst_bill  = (cope_payasst==1&cope_billstrategy==1)

svy: mean behavior_forgo behavior_payasst behavior_bill forgo_payasst forgo_bill payasst_bill


****************************
* Robustness and Attrition Tests
****************************

*Attrition inspections (Tables SI8 and SI9)*
sort id
by id: egen wave_count = count(wave)
sort wave_count
by wave_count: sum $HHdems $home_features

sum risky_behavior forego_expenses cope_payasst cope_billstrategy num_coping2 hhbill EI3previously $HHdems $home_features if wave==2 & wave_count==1
sum risky_behavior forego_expenses cope_payasst cope_billstrategy num_coping2 hhbill EI3previously $HHdems $home_features if wave==2 & (wave_count==2|wave_count==3)

sum risky_behavior forego_expenses cope_payasst cope_billstrategy num_coping2 hhbill EI3previously $HHdems $home_features if wave==3 & wave_count==2
sum risky_behavior forego_expenses cope_payasst cope_billstrategy num_coping2 hhbill EI3previously $HHdems $home_features if wave==3 & wave_count==3


* Robustness checks: Unbalanced Panel, changing the EI variables (Table SI4)*
svy: reg risky_behavior EI1previously EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_s14, replace excel ctitle(Risky Temp Behavior)

svy: reg risky_behavior lhhbill ldisconnect $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_s14, append excel ctitle(Risky Temp Behavior)

svy: reg forego_expenses EI1previously EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_s14, append excel ctitle(Forgo Expenses)

svy: reg forego_expenses lhhbill ldisconnect $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_s14, append excel ctitle(Forgo Expenses)

svy: reg cope_payasst EI1previously EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_s14, append excel ctitle(Payment Assistance)

svy: reg cope_payasst lhhbill ldisconnect $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_s14, append excel ctitle(Payment Assistance)

svy: reg cope_billstrategy EI1previously EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_s14, append excel ctitle(Bill Strategy)

svy: reg cope_billstrategy lhhbill ldisconnect $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_s14, append excel ctitle(Bill Strategy)

* Robustness checks: Number of coping strategies (Table SI6)*
poisson num_coping2 lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state  [pweight=weight]
outreg2 using table_s16, append excel ctitle(Count of Strategies)


* Robustness checks: Controlling for region and climate region, respectively, instead: Main models, Waves 2-4 (Table SI7)*
svy: reg risky_behavior lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state
outreg2 using table_si7, replace excel ctitle(Risky Temp Behavior)
svy: reg risky_behavior lhhbill EI3previously $HHdems $home_features wave2 wave3 $region
outreg2 using table_si7, append excel ctitle(Risky Temp Behavior)
svy: reg risky_behavior lhhbill EI3previously $HHdems $home_features wave2 wave3 $climateregion
outreg2 using table_si7, append excel ctitle(Risky Temp Behavior)

svy: reg forego_expenses lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si7, append excel ctitle(Forgo Expenses)
svy: reg forego_expenses lhhbill EI3previously $HHdems $home_features wave2 wave3 $region 
outreg2 using table_si7, append excel ctitle(Forgo Expenses)
svy: reg forego_expenses lhhbill EI3previously $HHdems $home_features wave2 wave3 $climateregion 
outreg2 using table_si7, append excel ctitle(Forgo Expenses)

svy: reg cope_payasst lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state
outreg2 using table_si7, append excel ctitle(Payment Assistance)
svy: reg cope_payasst lhhbill EI3previously $HHdems $home_features wave2 wave3 $region
outreg2 using table_si7, append excel ctitle(Payment Assistance)
svy: reg cope_payasst lhhbill EI3previously $HHdems $home_features wave2 wave3 $climateregion
outreg2 using table_si7, append excel ctitle(Payment Assistance)

svy: reg cope_billstrategy lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si7, append excel ctitle(Bill Strategy)
svy: reg cope_billstrategy lhhbill EI3previously $HHdems $home_features wave2 wave3 $region 
outreg2 using table_si7, append excel ctitle(Bill Strategy)
svy: reg cope_billstrategy lhhbill EI3previously $HHdems $home_features wave2 wave3 $climateregion 
outreg2 using table_si7, append excel ctitle(Bill Strategy)


*Robustness checks: Balanced Panel: Main models, Waves 2-4 (Table SI5)*
keep if balanced_panelist==1
sort id wave
order id wave
svyset id [pweight=weight_balanced]


svy: reg risky_behavior lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si5, replace excel ctitle(Risky Temp Behavior)

svy: reg forego_expenses lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si5, append excel ctitle(Forgo Expenses)

svy: reg cope_payasst lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si5, append excel ctitle(Payment Assistance)

svy: reg cope_billstrategy lhhbill EI3previously $HHdems $home_features wave2 wave3 i.state 
outreg2 using table_si5, append excel ctitle(Bill Strategy)



log close




